package xyz.yuzegod.megawalls.stats;

import com.google.gson.JsonObject;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.database.DataBase;
import xyz.yuzegod.megawalls.database.KeyValue;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.util.StringUtils;

public class KitStatsContainer
{
    private static DataBase database;
    private GamePlayer gamePlayer;
    private Classes classes;
    private int level;
    private int equipLevel;
    private int skillLevel;
    private int skill2Level;
    private int skill3Level;
    private int skill4Level;
    private int wins;
    private int games;
    private int finalKills;
    private int finalAssists;
    private int enderChest;
    private int masterPoints;
    private boolean enableGoldTag;
    private long playTime;
    private JsonObject inventory;
    
    public KitStatsContainer(final GamePlayer gamePlayer, final Classes classes) {
        this.gamePlayer = gamePlayer;
        this.classes = classes;
    }
    
    public void addLevel() {
        ++this.level;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("level", this.level), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addEquipLevel() {
        ++this.equipLevel;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("equipLevel", this.equipLevel), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addSkillLevel() {
        ++this.skillLevel;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("skillLevel", this.skillLevel), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addSkill2Level() {
        ++this.skill2Level;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("skill2Level", this.skill2Level), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addSkill3Level() {
        ++this.skill3Level;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("skill3Level", this.skill3Level), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addSkill4Level() {
        ++this.skill4Level;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("skill4Level", this.skill4Level), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addWins() {
        ++this.wins;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("wins", this.wins), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addGames() {
        ++this.games;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("games", this.games), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addFinalKills(final int amount) {
        this.finalKills += amount;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("finalKills", this.finalKills), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addFinalAssists(final int amount) {
        this.finalAssists += amount;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("finalAssists", this.finalAssists), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addEnderChest() {
        ++this.enderChest;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("enderChest", this.enderChest), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void giveMasterPoints(final int amount) {
        this.masterPoints += amount;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("masterPoints", this.masterPoints), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void takeMasterPoints(final int amount) {
        if (this.masterPoints - amount < 0) {
            return;
        }
        this.masterPoints -= amount;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("masterPoints", this.masterPoints), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void addPlayTime(final long time) {
        this.playTime += time;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("playTime", this.playTime), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void setEnableGoldTag(final boolean enableGoldTag) {
        this.enableGoldTag = enableGoldTag;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("enableGoldTag", String.valueOf(enableGoldTag)), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public void updateInventory(final JsonObject inventory) {
        this.inventory = inventory;
        KitStatsContainer.database.dbUpdate("classes_" + this.classes.getName(), new KeyValue("inventory", (inventory == null) ? "null" : inventory.toString()), new KeyValue("uuid", this.gamePlayer.getUuid().toString()));
    }
    
    public String upgradePercent() {
        final double percent = (this.equipLevel + this.skillLevel + this.skill2Level + this.skill3Level + this.skill4Level + this.enderChest - 8) / 16.0;
        return ((percent >= 1.0) ? "§a§l" : "§e") + StringUtils.percent(percent);
    }
    
    public boolean isMaxed() {
        return this.equipLevel + this.skillLevel + this.skill2Level + this.skill3Level + this.skill4Level + this.enderChest - 8 == 16;
    }
    
    public GamePlayer getGamePlayer() {
        return this.gamePlayer;
    }
    
    public Classes getClasses() {
        return this.classes;
    }
    
    public int getLevel() {
        return this.level;
    }
    
    public void setLevel(final int level) {
        this.level = level;
    }
    
    public int getEquipLevel() {
        return this.equipLevel;
    }
    
    public void setEquipLevel(final int equipLevel) {
        this.equipLevel = equipLevel;
    }
    
    public int getSkillLevel() {
        return this.skillLevel;
    }
    
    public void setSkillLevel(final int skillLevel) {
        this.skillLevel = skillLevel;
    }
    
    public int getSkill2Level() {
        return this.skill2Level;
    }
    
    public void setSkill2Level(final int skill2Level) {
        this.skill2Level = skill2Level;
    }
    
    public int getSkill3Level() {
        return this.skill3Level;
    }
    
    public void setSkill3Level(final int skill3Level) {
        this.skill3Level = skill3Level;
    }
    
    public int getSkill4Level() {
        return this.skill4Level;
    }
    
    public void setSkill4Level(final int skill4Level) {
        this.skill4Level = skill4Level;
    }
    
    public int getWins() {
        return this.wins;
    }
    
    public void setWins(final int wins) {
        this.wins = wins;
    }
    
    public int getGames() {
        return this.games;
    }
    
    public void setGames(final int games) {
        this.games = games;
    }
    
    public int getFinalKills() {
        return this.finalKills;
    }
    
    public void setFinalKills(final int finalKills) {
        this.finalKills = finalKills;
    }
    
    public int getFinalAssists() {
        return this.finalAssists;
    }
    
    public void setFinalAssists(final int finalAssists) {
        this.finalAssists = finalAssists;
    }
    
    public int getEnderChest() {
        return this.enderChest;
    }
    
    public void setEnderChest(final int enderChest) {
        this.enderChest = enderChest;
    }
    
    public int getMasterPoints() {
        return this.masterPoints;
    }
    
    public void setMasterPoints(final int masterPoints) {
        this.masterPoints = masterPoints;
    }
    
    public boolean isEnableGoldTag() {
        return this.enableGoldTag;
    }
    
    public long getPlayTime() {
        return this.playTime;
    }
    
    public void setPlayTime(final long playTime) {
        this.playTime = playTime;
    }
    
    public JsonObject getInventory() {
        return this.inventory;
    }
    
    public void setInventory(final JsonObject inventory) {
        this.inventory = inventory;
    }
    
    static {
        KitStatsContainer.database = MegaWalls.getInstance().getDataBase();
    }
}
